package com.wanqing.controller.user;

import com.wanqing.dto.UserLoginDTO;
import com.wanqing.properties.JwtProperties;
import com.wanqing.result.Result;
import com.wanqing.service.UserService;
import com.wanqing.vo.UserLoginVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@Tag(name = "C端-用户相关接口")
@RequestMapping("/user/user")
public class UserController {

    @Resource
    private UserService userService;

    @Resource
    private JwtProperties jwtProperties;

//    @PostMapping("/login")
//    @Operation(summary = "微信登录")
//    public Result<UserLoginVO> login(@RequestBody UserLoginDTO userLoginDTO) {
//        User user = userService.wxLogin(userLoginDTO);
//        Map<String, Object> claims = new HashMap<>();
//        claims.put(JwtClaimsConstant.USER_ID, user.getId());
//        String token = JwtUtil.createJWT(jwtProperties.getUserSecretKey(), jwtProperties.getUserTtl(), claims);
//        UserLoginVO userLoginVO = UserLoginVO.builder().id(user.getId()).openid(user.getOpenid()).token(token).build();
//        return Result.success(userLoginVO);
//    }

    @GetMapping("login/getCode")
    @Operation(summary = "获取短信验证码")
    public Result<String> getCode(@RequestParam String phone) {
        userService.getSMSCode(phone);
        return Result.success();
    }

    @PostMapping("login")
    @Operation(summary = "登录")
    public Result<UserLoginVO> login(@RequestBody UserLoginDTO userLoginDTO) {
        UserLoginVO login = userService.login(userLoginDTO);
        return Result.success(login);
    }
}
